package com.sunfield.windpower;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

import com.sunfield.baseframe.base.BaseApplication;
import com.sunfield.baseframe.http.HttpHeader;
import com.sunfield.windpower.http.HttpHeadProviderImpl;

import org.androidannotations.annotations.EApplication;

/**
 * Created by DELL on 2017/2/6.
 */
@EApplication
public class MyApplication extends BaseApplication {
    private static ApplicationInfo applicationInfo;

    @Override
    public void onCreate() {
        super.onCreate();
        HttpHeader.setHttpHeadProvider(new HttpHeadProviderImpl());
    }

    @Override
    public void logout() {
    }

    public static String getMetaData(String key) {
        if (applicationInfo == null) {
            try {
                applicationInfo = getInstance().getPackageManager().getApplicationInfo(getInstance().getPackageName(), PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
        return applicationInfo.metaData.getString(key);
    }

    public static void removeAllCookies(){
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getInstance());
        CookieManager cookieManager = CookieManager.getInstance();

        cookieManager.setAcceptCookie(true);
        cookieManager.removeSessionCookie();

        cookieManager.removeAllCookie();
        cookieSyncManager.sync();
    }
}
